package com.wangrui.test;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import com.wangrui.dao.BinaryMapper;
import com.wangrui.dao.UserMapper3;
import com.wangrui.dao.UserMapper6;
import com.wangrui.entity.BinaryInfo;
import com.wangrui.entity.User;

public class MyBatisTestForBinary {

    private static SqlSessionFactory getSessionFactory() {
        SqlSessionFactory sessionFactory = null;
        String resource = "configuration.xml";
        try {
            sessionFactory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsReader(resource));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return sessionFactory;
    }


    @Test
    public void testAddBinary() throws UnsupportedEncodingException {
        SqlSessionFactory factory = getSessionFactory();
        //默认是手动提交的
        SqlSession session = factory.openSession();
        BinaryMapper mapper = session.getMapper(BinaryMapper.class);
        BinaryInfo info = new BinaryInfo();
        info.setId(1);
        info.setPassword("六度人和");
        info.setInfo("六度人和");
        info.setImage("图片");
        mapper.insertBinary(info);
        session.commit();
        session.close();
    }

    @Test
    public void testSelectBinary() {
        SqlSessionFactory factory = getSessionFactory();
        //默认是手动提交的
        SqlSession session = factory.openSession();
        BinaryInfo info = session.selectOne("com.wangrui.dao.BinaryMapper.selectBinary");
        System.out.println("password:" + info.getPassword());
        System.out.println("info:" + info.getInfo());
        System.out.println("image:" + info.getImage());
    }
}
